package com.perfect.controller;

import com.perfect.base.BaseController;
import com.perfect.query.DiscountQuery;
import com.perfect.service.DiscountService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 优惠券管理
 */

@Controller
@RequestMapping("discount")
public class DiscountController extends BaseController {


    @Resource
    private DiscountService discountService;

    /**
     * 进入优惠券管理页面
     *
     * @return
     */

    @RequestMapping("index")
    public String index() {
        return "discount/discount_index";
    }

    /**
     * 多条件查询优惠券
     *
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> queryDiscount(DiscountQuery discountQuery) {
        System.out.println(discountQuery.getName());
        return discountService.listDiscountByParams(discountQuery);
    }

    /**
     * 查询所有优惠券类型
     *
     * @return
     */
    @RequestMapping("queryDiscountType")
    @ResponseBody
    public List<Map<String, Object>> queryDiscountType() {
        return discountService.listDiscountType();
    }

    /**
     * 查询优惠券详情
     * @param id
     * @param request
     * @return
     */
    @RequestMapping("discount_data")
    public String discountData(Integer id, HttpServletRequest request) {
        System.out.println(id);
        request.setAttribute("discountData", discountService.listDiscountDataById(id));
        return "discount/discount_data";
    }

    /**
     * 优惠券使用详情 和 多条件查询
     * @param discountQuery
     * @return
     */
//    @RequestMapping("discountUse")
//    @ResponseBody
//    public Map<String, Object> queryDiscountUse(DiscountQuery discountQuery) {
//        return null;
//    }
}
